<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->url->theme.'script/settings.js'); ?>

<?php
    if(!isset($model) || !$model) $model=new Setting();
    $languages=Language::model()->all;
?>

<div class="grid_12">
    <div id="settings-popup" class="module">
        <h2>
            <div class="popup-head">
                <span><?php echo $model->id ? Yii::t('settings','setting').' "'.$model->name.'"' : Yii::t('settings','newSetting'); ?></span>
                <?php echo CHtml::link('','#',array(
                    'class'=>'close-link',
                    'onClick'=>'Main.closePopup($("#settings-popup")); return false;',
                )); ?>
            </div>
        </h2>

        <div class="module-body">

        <?php $form=$this->beginWidget('CActiveForm', array(
            'id'=>'setting-form',
            'action'=>Yii::app()->createUrl('admin/settings/change'),
            'method'=>'post',
            'enableAjaxValidation'=>true,
            'clientOptions'=>array(
                'validateOnSubmit'=>true,
                'validateOnChange'=>false,
            ),
            'htmlOptions'=>array(
               'enctype'=>'multipart/form-data',
            ),
        )); ?>

        <?php echo CHtml::errorSummary(array($model)); ?>

            <?php echo $form->hiddenField($model,'id'); ?>
            <?php echo $form->hiddenField($model,'type'); ?>
            <?php //echo CHtml::hiddenField(Yii::app()->request->csrfTokenName,Yii::app()->request->csrfToken); ?>

            <?php if(!$model->id): ?>
                <?php Yii::app()->controller->renderPartial('admin.views.settings.__columnForNewSetting',array(
                    'model'=>$model,
                    'form'=>$form,
                )) ?>
            <?php endif; ?>

            <?php echo $form->label($model,'name',array('class'=>'main-label')); ?>

            <?php $this->widget('MultiLangFields',array('settings'=>array(
                'model'=>$model,
                'name'=>'name',
                'divClass'=>'formline',
                'inputClass'=>'input-short'
            ))); ?>

            <?php echo $form->label($model,'value',array('class'=>'main-label')); ?>

            <div class="formline">

                <?php if($model->type!=='text'): ?>
                    <?php echo $form->label($model,'value'); ?>
                <?php endif; ?>

                <?php Yii::app()->controller->renderPartial('admin.views.settings.__settingValueField',array(
                    'model'=>$model,
                    'form'=>$form,
                    'type'=>$model->type,
                )); ?>

            </div>

            <?php echo $form->label($model,'description',array('class'=>'main-label')); ?>

            <?php $this->widget('MultiLangFields',array('settings'=>array(
                'model'=>$model,
                'name'=>'description',
                'divClass'=>'formline',
                'inputClass'=>'input-short'
            ))); ?>

            <fieldset>

                <?php echo CHtml::submitButton(Yii::t('main','save'),array(
                    'class'=>'submit-green left',
                )); ?>

                <?php echo CHtml::link(Yii::t('main','remove'), Yii::app()->createUrl('admin/settings/delete', array('id'=>$model->id)),array(
                    'class'=>'submit-green left',
                    'onClick'=>'return confirm("'.Yii::t('settings','confirmDelete',array('{setting}'=>$model->name)).'");'
                )); ?>

            </fieldset>

        <?php $this->endWidget(); ?>

        </div> <!-- module-body -->

    </div> <!-- module -->
</div> <!-- grid_12 -->
